﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Globalization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Stonecode.Solar.ParticleEffectEditor
{
    using XnaColor = Microsoft.Xna.Framework.Color;
    using GdiColor = System.Drawing.Color;
using Stonecode.Solar.ParticleEngine;

    public class Win_EmitterSettings
    {
        #region Properties

        // Name of the texture used by this particle system.
        public string TextureName = null;

        public string EmitterName;

        // Maximum number of particles that can be displayed at one time.
        // This should only be set by the constructor since this is the 
        // size of the array

        private uint _maxParticles = 100;
        public uint MaxParticles { get { return _maxParticles; } }

        public float ParticlesPerSecond { get; set; }
        // How long these particles will last.

        [System.ComponentModel.Category("Position")]
        [System.ComponentModel.Description("The offset from the emitter position in which it fires")]
        public Vector3 Offset { get; set; }

        [System.ComponentModel.Category("Life")]
        public TimeSpan Duration { get; set; }

        public bool Enabled { get; set; }

        // If greater than zero, some particles will last a shorter time than others.

        [Category("Life")]
        public float DurationRandomness { get; set; }


        // Controls how much particles are influenced by the velocity of the object
        // which created them. You can see this in action with the explosion effect,
        // where the flames continue to move in the same direction as the source
        // projectile. The projectile trail particles, on the other hand, set this
        // value very low so they are less affected by the velocity of the projectile.

        [Category("Velocity")]
        public float EmitterVelocitySensitivity { get; set; }


        // Range of values controlling how much X and Z axis velocity to give each
        // particle. Values for individual particles are randomly chosen from somewhere
        // between these limits.

        [Category("Velocity")]
        public float MinHorizontalVelocity { get; set; }

        [Category("Velocity")]
        public float MaxHorizontalVelocity { get; set; }


        // Range of values controlling how much Y axis velocity to give each particle.
        // Values for individual particles are randomly chosen from somewhere between
        // these limits.

        [Category("Velocity")]
        public float MinVerticalVelocity { get; set; }

        [Category("Velocity")]
        public float MaxVerticalVelocity { get; set; }

        // Controls how the particle velocity will change over their lifetime. If set
        // to 1, particles will keep going at the same speed as when they were created.
        // If set to 0, particles will come to a complete stop right before they die.
        // Values greater than 1 make the particles speed up over time.

        [Category("Velocity")]
        public float EndVelocity { get; set; }


        // Range of values controlling the particle color and alpha. Values for
        // individual particles are randomly chosen from somewhere between these limits.

        [Category("Color")]
        [EditorAttribute(typeof(System.Windows.Forms.ColorDialog), typeof(System.Drawing.Design.ColorEditor))]
        //
        //[EditorAttribute(typeof(System.Windows.Forms.ColorDialog), typeof(System.Drawing.Design.UITypeEditor))]

        public GdiColor MinColor { get; set; }

        [Category("Color")]
        [Editor(typeof(System.Windows.Forms.ColorDialog), typeof(System.Drawing.Design.ColorEditor))]

        public GdiColor MaxColor { get; set; }

        [Category("Color")]
        public float FadeIn { get; set; }

        [Category("Color")]
        public float FadeOut { get; set;}

        [Category("Color")]
        public float FadeMultiplierIn { get; set; }
        
        [Category("Color")]
        public float FadeMultiplierOut { get; set; }

        // Range of values controlling how fast the particles rotate. Values for
        // individual particles are randomly chosen from somewhere between these
        // limits. If both these values are set to 0, the particle system will
        // automatically switch to an alternative shader technique that does not
        // support rotation, and thus requires significantly less GPU power. This
        // means if you don't need the rotation effect, you may get a performance
        // boost from leaving these values at 0.

        [Category("Rotation")]
        public float MinRotateSpeed { get; set; }

        [Category("Rotation")]
        public float MaxRotateSpeed { get; set; }

        [Category("Rotation")]
        public int RotationVariation { get; set; }


        // Range of values controlling how big the particles are when first created.
        // Values for individual particles are randomly chosen from somewhere between
        // these limits.
        [Category("Size")]
        public float MinStartSize { get; set; }

        [Category("Size")]
        public float MaxStartSize { get; set; }


        // Range of values controlling how big particles become at the end of their
        // life. Values for individual particles are randomly chosen from somewhere
        // between these limits.

        [Category("Size")]
        public float MinEndSize { get; set; }

        [Category("Size")]
        public float MaxEndSize { get; set; }


        // Color Blend Options

        [Category("Blend Options Color")]
        public Blend ColorSourceBlend { get; set; }

        [Category("Blend Options Color")]
        public Blend ColorDestinationBlend { get; set; }


        [Category("Blend Options Color")]
        public BlendFunction ColorBlendFunction { get; set; }


        // Alpha blending settings.

        [Category("Blend Options Alpha")]
        public Blend AlphaSourceBlend { get; set; }


        [Category("Blend Options Alpha")]
        public Blend AlphaDestinationBlend { get; set; }


        [Category("Blend Options Alpha")]
        public BlendFunction AlphaBlendFunction { get; set; }


        [Category("Blend Options Alpha")]
        public Color BlendFactor { get; set; }

        #endregion


        #region Forces

       
        [Category("Forces")]
        public Vector3 Gravity { get; set; }

        [Category("Forces")]
        public bool UseBlackHole { get; set; }
        [Category("Forces")]
        public Vector3 BlackHole_Position { get; set; }
        [Category("Forces")]
        public float BlackHole_Strength { get; set; }

        [Category("Forces")]
        public float RadialGravity { get; set; }

        #endregion

        public void SetFromEmitterSettings(EmitterSettings e)
        {
            AlphaSourceBlend = e.AlphaSourceBlend;
            AlphaDestinationBlend = e.AlphaDestinationBlend;
            AlphaBlendFunction = e.AlphaBlendFunction;;

            BlendFactor  = e.BlendFactor;

            ColorDestinationBlend = e.ColorDestinationBlend;
            ColorSourceBlend = e.ColorSourceBlend;
            ColorBlendFunction = e.ColorBlendFunction;

            Offset = e.Offset;

            Duration = e.Duration;
            DurationRandomness = e.DurationRandomness;
            EmitterName = e.EmitterName;
            EmitterVelocitySensitivity = e.EmitterVelocitySensitivity;
            Enabled = e.Enabled;
            EndVelocity = e.EndVelocity;
            

            MaxColor = GdiColor.FromArgb(e.MaxColor.A, e.MaxColor.R, e.MaxColor.G, e.MaxColor.B);
            MinColor = GdiColor.FromArgb(e.MinColor.A, e.MinColor.R, e.MinColor.G, e.MinColor.B);

            FadeIn = e.FadeIn;
            FadeOut = e.FadeOut;
            FadeMultiplierIn = e.FadeMultiplierIn;
            FadeMultiplierOut = e.FadeMultiplierOut;
            
            _maxParticles = e.MaxParticles;

            MaxEndSize = e.MaxEndSize;
            MaxHorizontalVelocity = e.MaxHorizontalVelocity;
            MaxRotateSpeed = e.MaxRotateSpeed;
            MaxStartSize = e.MaxStartSize;
            MaxVerticalVelocity = e.MaxVerticalVelocity;
            
            MinEndSize = e.MinEndSize;
            MinHorizontalVelocity = e.MinHorizontalVelocity;
            MinRotateSpeed = e.MinRotateSpeed;
            MinStartSize = e.MinStartSize;
            MinVerticalVelocity = e.MinVerticalVelocity;
            ParticlesPerSecond = e.ParticlesPerSecond;
            RotationVariation = e.RotationVariation;
            
            TextureName = e.TextureName;

            // Forces
            Gravity = e.Gravity;
            //UseBlackHole = e.UseBlackHole;
            BlackHole_Position = e.BlackHole_Position;
            BlackHole_Strength = e.BlackHole_Strength;
            RadialGravity = e.RadialGravity;

        }
        public void GetEmitterSettings(EmitterSettings e)
        {
            // Will be replaced for 4.0...
            e.AlphaSourceBlend = AlphaSourceBlend;
            e.AlphaDestinationBlend = AlphaDestinationBlend;
            e.AlphaBlendFunction = AlphaBlendFunction; ;

            e.BlendFactor = BlendFactor;

            e.ColorDestinationBlend = ColorDestinationBlend;
            e.ColorSourceBlend = ColorSourceBlend;
            e.ColorBlendFunction = ColorBlendFunction;

            e.Offset = Offset;

            e.Duration = Duration;
            e.DurationRandomness = DurationRandomness;
            e.EmitterName = EmitterName;
            e.EmitterVelocitySensitivity = EmitterVelocitySensitivity;
            e.Enabled = Enabled;
            e.EndVelocity = EndVelocity;
            
            e.MaxColor = new XnaColor(MaxColor.R, MaxColor.G, MaxColor.B, MaxColor.A);
            e.MinColor = new XnaColor(MinColor.R, MinColor.G, MinColor.B, MinColor.A);

            e.FadeIn = FadeIn;
            e.FadeOut = FadeOut;
            e.FadeMultiplierIn = FadeMultiplierIn;
            e.FadeMultiplierOut = FadeMultiplierOut;

            e.MaxEndSize = MaxEndSize;
            e.MaxHorizontalVelocity = MaxHorizontalVelocity;
            e.MaxRotateSpeed = MaxRotateSpeed;
            e.MaxStartSize = MaxStartSize;
            e.MaxVerticalVelocity = MaxVerticalVelocity;
            
            e.MinEndSize = MinEndSize;
            e.MinHorizontalVelocity = MinHorizontalVelocity;
            e.MinRotateSpeed = MinRotateSpeed;
            e.MinStartSize = MinStartSize;
            e.MinVerticalVelocity = MinVerticalVelocity;
            e.ParticlesPerSecond = ParticlesPerSecond;
            e.RotationVariation = RotationVariation;
            
            e.TextureName = TextureName;

            e.Gravity = Gravity;
            //e.UseBlackHole = UseBlackHole;
            e.BlackHole_Position = BlackHole_Position;
            e.BlackHole_Strength = BlackHole_Strength;
            e.RadialGravity = RadialGravity;
            
        }
    }
}
